<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<!DOCTYPE html>
<html lang="en">
<head>
    <!-- header -->
    <%@ include file="/WEB-INF/views/include/header.jsp" %>
    <style>
        .nav {
            margin-left: 0;
        }

        .nav > li > a:focus, .nav > li > a:hover {
            text-decoration: none;
            background-color: #33CCFF !important;
        }

        .modal-dialog {
            z-index: 9999999;
        }

        @media (min-width: 768px) {
            .modal-content {
                -webkit-box-shadow: 0 5px 15px rgba(0, 0, 0, .5);
                box-shadow: 0 -2px 20px rgba(0, 0, 0, .5) !important;
            }
        }

        /*.ui-jqgrid-htable th div{*/
        /*text-align: center;*/
        /*}*/
    </style>
</head>
<body class="bgcolor">

<!-- /section:basics/navbar.layout -->
<table></table>
<div class="main-container" id="main-container">


    <!-- /section:basics/sidebar -->
    <div class="main-content">
        <div class="main-content-inner">
            <div class="page-content">
                <!-- /section:settings.box -->
                <div class="row">
                    <div class="col-xs-12">
                        <div class="pull-left">
                            <button class="btn btn-sm btn-info" id="query">条件搜索</button>
                            <button class="btn btn-sm btn-default" id="ownerUnit">业主单位</button>
                            <button class="btn btn-sm btn-default" id="approvalDepartment">审批部门</button>
                            <button class="btn btn-sm btn-default" id="supervision">督查组</button>
                            <div style="margin: 3px 0px;">
                                <button class="btn btn-sm btn-success" id="exportSummary">导出报表</button>
                                <button class="btn btn-sm btn-warning" id="personRank1">个人排名</button>
                                <button class="btn btn-sm btn-warning" id="departRank1">单位排名</button>
                                <button class="btn btn-sm btn-warning" id="personRank">个人排名</button>
                                <button class="btn btn-sm btn-warning" id="departRank">部门排名</button>
                                <button class="btn btn-sm btn-danger" id="delete" style="display: none;">删除</button>
                            </div>

                            <%--<shiro:hasPermission name="modules:sys:dept:excel">
                                <button class="btn btn-sm btn-pink" id="export">导出</button>
                            </shiro:hasPermission>--%>
                        </div>
                        <div class="pull-right">
                            <button class="btn btn-sm btn-danger" id="gradepoint">考核记录</button>
                            <button class="btn btn-sm btn-danger" id="showSummary">考核汇总</button>
                        </div>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-12">
                        <!-- PAGE CONTENT BEGINS -->
                        <!-- jqGrid表格 -->
                        <table id="gridTable"></table>
                        <!-- jqGrid工具类 -->
                        <div id="gridPager"></div>
                        <!-- 查询对话框 -->
                        <div style="display: none;">
                            <div class="row" id="queryDialog"></div>
                        </div>
                        <!-- PAGE CONTENT ENDS -->
                    </div><!-- /.col -->
                </div><!-- /.row -->
            </div><!-- /.page-content -->
        </div>
    </div><!-- /.main-content -->

    <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
        <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
    </a>


</div><!-- /.main-container -->
</div>
<!-- footer -->
<script src="<s:url value="/assets/web/common/bootstrapvalidator/dist/js/bootstrapValidator.js"></s:url>"></script>
<%@ include file="/WEB-INF/views/include/footer.jsp" %>
<!-- dialog -->
<%@ include file="/WEB-INF/views/include/dialog.jsp" %>


<script type="text/javascript">
    //基本路径
    var baseUrl = "<s:url value="/scoresummary"></s:url>/"
    //jqgrid的表格高度
    var height = 320;
    //jqgrid表格行头的中文
    var colNames = ['', '序号', '考核对象', '最终得分', '排名', '所属部门', '汇总时间'];
    var colModel = [
        {name: 'sysId', width: 60, hidden: true, key: true},
        {name: 'sysId', index: 'sysId', width: 190, editable: true},
        {name: 'checkObject', index: 'checkObject', width: 164, editable: true},
        {name: 'score', index: 'score', width: 140, editable: true, cellattr: addCellAttr},
        {name: 'rank', index: 'rank', width: 60, editable: true, cellattr: addCellAttr},
        {name: 'checkDept', index: 'checkDept', width: 280, editable: true},
        {name: 'summaryDate', index: 'summaryDate', width: 140, editable: true}
    ];

    //jqgrid的具体执行方法
    jqgrid({
        autoScroll: false,
        shrinkToFit: false,
        gridTableId: "#gridTable",
        gridPagerId: "#gridPager",
        onSelectRow: function (rowid, status) {
            rowids = $('#gridTable').jqGrid('getGridParam', 'selarrrow');
        },
        onSelectAll: function (aRowids, status) {
            rowids = $('#gridTable').jqGrid('getGridParam', 'selarrrow');
        },
        gridComplete: function () {
            var rowIds = jQuery("#gridTable").jqGrid('getDataIDs');
            for (var k = 0; k < rowIds.length; k++) {
                var flag = false;
                for (var i = 0; i < rowids.length; i++) {
                    if (rowids[i] == rowIds[k]) {
                        flag = true;
                        continue;
                    }
                }
                if (flag && flag == true) {
                    jQuery("#gridTable").setSelection(rowIds[k], true);
                }
            }
        }
    });

    //加载查询对话框
    $("#queryDialog").load(getUrl("filter"));

    //重置表单
    function reset() {
        resetForm("#formDialog form");
    }

    var exportData = '';
    //显示查询对话框
    var queryDialog = $("#queryDialog");
    $("#query").click(function () {
        branchType = "";
        showDialog({
            dialogTitle: '查询对话框',
            dialogBody: queryDialog,
            dialogFoot: "<button type='button' class='btn btn-primary' onclick='query()'>查询</button>" +
                "<button type='button' class='btn btn-pink' onclick='reset()'>重置</button>" +
                "<button type='button' class='btn btn-default' data-dismiss='modal'>关闭</button>"
        });
    });

    //具体查询方法
    function query() {

        exportData = $('#formDialog form').serialize();
        seachJqgird("#gridTable", "#formDialog form");
        $("#formDialog").modal('hide');
    }

    //更新操作
    $("#edits").click(function () {
        showEditView();
    });

    //考核汇总
    $("#showSummary").click(function () {
        window.location.href = '/scoresummary';
    });

    //考核记录
    $("#gradepoint").click(function () {
        window.location.href = '/gradepoint';
    });

    $(function () {
        $("#departRank").css("display", "none");
        $("#departRank1").css("display", "none");
        $("#personRank").css("display", "none");
        $("#personRank1").css("display", "none");
    })

    var departRank = false;
    var branchType = "";
    //业主单位
    $("#ownerUnit").click(function () {
        $("#gridTable").setGridParam().showCol("checkDept");
        departRank = false;
        branchType = "0";
        $("#departRank").attr("style", "display:none;");
        $("#personRank").attr("style", "display:none;");

        $("#departRank1").attr("style", "display:inline;");
        $("#personRank1").attr("style", "display:inline;");
        var url = '/scoresummary';
        //先清空条件,多次调用时查询条件会累加
        $('#gridTable').jqGrid('clearGridData');
        $("#gridTable").jqGrid('setGridParam', {
            url: url,
            datatype: 'json',
            postData: {
                'branchType': "0",
                'departRank': false
            }, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
    });

    //业主单位->(个人排名)
    $("#personRank1").click(function () {
        $("#gridTable").setGridParam().showCol("checkDept");
        departRank = false;
        branchType = "0";
        var url = '/scoresummary';
        //先清空条件,多次调用时查询条件会累加
        $('#gridTable').jqGrid('clearGridData');
        $("#gridTable").jqGrid('setGridParam', {
            url: url,
            datatype: 'json',
            postData: {
                'branchType': "0",
                'departRank': false
            }, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
    });

    //业主单位->(单位排名)
    $("#departRank1").click(function () {
        $("#gridTable").setGridParam().hideCol("checkDept");
        departRank = true;
        branchType = "0";
        var url = '/scoresummary';
        //先清空条件,多次调用时查询条件会累加
        $('#gridTable').jqGrid('clearGridData');
        $("#gridTable").jqGrid('setGridParam', {
            url: url,
            datatype: 'json',
            postData: {
                'branchType': "0",
                'departRank': true
            }, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
    });

    //审批部门
    $("#approvalDepartment").click(function () {
        $("#gridTable").setGridParam().showCol("checkDept");
        departRank = false;
        branchType = "1";
        $("#departRank").attr("style", "display:inline;");
        $("#personRank").attr("style", "display:inline;");

        $("#departRank1").attr("style", "display:none;");
        $("#personRank1").attr("style", "display:none;");
        var url = '/scoresummary';
        $("#gridTable").jqGrid('setGridParam', {
            url: url,
            datatype: 'json',
            postData: {
                'branchType': "1",
                'departRank': false
            }, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
    });

    //审批部门->(个人排名)
    $("#personRank").click(function () {
        $("#gridTable").setGridParam().showCol("checkDept");
        departRank = false;
        branchType = "1";
        var url = '/scoresummary';
        //先清空条件,多次调用时查询条件会累加
        $('#gridTable').jqGrid('clearGridData');
        $("#gridTable").jqGrid('setGridParam', {
            url: url,
            datatype: 'json',
            postData: {
                'branchType': "1",
                'departRank': false
            }, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
    });

    //审批部门->(部门排名)
    $("#departRank").click(function () {
        $("#gridTable").setGridParam().hideCol("checkDept");
        departRank = true;
        branchType = "1";
        var url = '/scoresummary';
        //先清空条件,多次调用时查询条件会累加
        $('#gridTable').jqGrid('clearGridData');
        $("#gridTable").jqGrid('setGridParam', {
            url: url,
            datatype: 'json',
            postData: {
                'branchType': "1",
                'departRank': true
            }, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
    });

    //督查组
    $("#supervision").click(function () {
        $("#gridTable").setGridParam().showCol("checkDept");
        departRank = false;
        branchType = "4";
        $("#departRank").attr("style", "display:none;");
        $("#personRank").attr("style", "display:none;");

        $("#departRank1").attr("style", "display:none;");
        $("#personRank1").attr("style", "display:none;");
        var url = '/scoresummary';
        $("#gridTable").jqGrid('setGridParam', {
            url: url,
            datatype: 'json',
            postData: {
                'branchType': "4",
                'departRank': false
            }, //发送数据
            page: 1
        }).trigger("reloadGrid"); //重新载入
    });

    //删除
    $("#delete").click(function () {
        showDeleteView();
    });

    //显示删除对话框
    function showDeleteView() {
        showDeleteDialog({
            url: getUrl("delete"),
            tableId: "#gridTable",
            confirmTitle: "确认对话框",
            confirmMessage: "是否确定删除?",
            confirmOk: "确定",
            confirmCancel: "取消",
            successMessage: "删除成功",
            successTitle: "消息对话框",
            failMessage: "删除失败",
            failTitle: "消息对话框",
            errorTitle: "警告提示框",
            errorMessage: "您当前尚未选中一行，请选择后再试",
            errorOk: "确定"
        });
    }

    //显示创建对话框
    $("#create").click(function () {
        loadDialog({
            dialogTitle: '创建对话框',
            dialogUrl: getUrl("create"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="create()">提交审核</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });

    //分类编辑框
    $("#createCla").click(function () {
        loadDialog({
            dialogTitle: '创建对话框',
            dialogUrl: getUrl("createCla"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="create()">添加</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });

    //保存数据
    function create() {
        executeSaveOrUpdate({
            formId: "#formDialog form",
            dialogId: "#formDialog",
            url: getUrl("create"),
            tableId: "#gridTable",
            successMessage: "保存成功",
            successTitle: '保存对话框',
            //failMessage: '保存失败',
            failTitle: '消息对话框'
        });
    }

    /**
     * 导出表头选择
     */
    $("#exportSummary").click(function () {
        loadDialog({
            dialogTitle: '导出绩效汇总报表',
            dialogUrl: getUrl("formHead"),
            dialogFoot: '<button type="button" class="btn btn-primary" onclick="exports()">确认</button>' +
                '<button type="button" class="btn btn-pink" onclick="reset()">重置</button>' +
                '<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>'
        });
    });

    function exports() {
        var exportData = '';//钩选表头数据
        exportData = $('#formDialog #formHeads').serialize();
        var win = confirm("确认导出？");
        if (win == true) {
            exportData = $('#formDialog form').serialize();
            var url = "/export/exportSummaryPointDetail?" + exportData + "&departRank=" + departRank + "&branchType=" + branchType + "&sysIds=" + rowids;
            console.log(url);
            window.open(url);
        }
    }

    jQuery("#gridTable").jqGrid('setLabel', 0, '序号', 'labelstyle');

    //清空选中行
    $("#cancelChecked").click(function () {
        $("#gridTable").jqGrid('resetSelection');
        rowids = [];
    });
    var rowids = [];//选中行id

    /**
     * 重写Array
     */
    Array.prototype.remove = function (val) {
        var index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    };

    /**
     * 重写Array
     */
    Array.prototype.indexOf = function (val) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] == val) return i;
        }
        return -1;
    };

    /**
     * 给表格字体添加样式
     * @param rowId
     * @param val
     * @param rawObject
     * @param cm
     * @param rdata
     * @returns {string}
     */
    function addCellAttr(rowId, val, rawObject, cm, rdata) {
        return "style='color:red;font-weight:800;'";
    }

</script>

</body>
</html>